
#pragma once

#include <QMenuBar>
#include <QMenu>
#include <rviz_common/display_context.hpp>
#include <controller_msgs/srv/control_cmd.hpp>
#include <controller_msgs/srv/mission_cfg.hpp>
#include "rviz_custom_plugins/utils/project_manager.h"
#include "rviz_custom_plugins/utils/widget_manager.h"


using rviz_common::DisplayContext;
using controller_msgs::srv::ControlCmd;
using controller_msgs::srv::MissionCfg;
using rviz_custom_plugins::utils::ProjectManager;
using rviz_custom_plugins::utils::WidgetManager;


namespace gcs
{


namespace widgets {

    
class MenuBar : public QMenuBar {
    Q_OBJECT

public:
    explicit MenuBar(QWidget *parent = nullptr);

    void initialize(DisplayContext * context);

protected:
    DisplayContext * getDisplayContext() const;
    
private:

    DisplayContext * context;
    rclcpp::Node::SharedPtr node;
    rclcpp::Client<ControlCmd>::SharedPtr oprCmdClient;
    rclcpp::Client<MissionCfg>::SharedPtr missionCfgClient;
    QPointer<ProjectManager> projectManager;
    QPointer<WidgetManager> widgetManager;

    QString projectFolder;

    QMenu *projectMenu;
    QMenu *editMenu;
    QMenu *modeMenu;
    QMenu *opMenu;
    QMenu *manageMenu;
    QMenu *dataMenu;
    QMenu *viewMenu;
    QMenu *helpMenu;

    void createProjectBtnClicked();
    void loadProjectBtnClicked();
    void saveProjectBtnClicked();
    void closeProjectBtnClicked();
    
    void uploadMapBtnClicked();
    void uploadMissionBtnClicked();
    void snapshotBtnClicked();
    bool packJsonFiles(const QString& sourceDirPath, const QString& outputFilePath);

    void handleProjectLoaded(QSharedPointer<QVariantMap> projectData);
    // void handleProjectSaved(QSharedPointer<QVariantMap> projectData);
    void handleProjectClosed(QSharedPointer<QVariantMap> projectData);

    
};

}

}
